package com.ddyang.Webflux.config;

import com.ddyang.Webflux.handler.MyWebHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RouterFunctions.route;


/**
 * 新的响应式编程为真正的reactive式编程写法
 */
@Configuration
public class RouterConfig {
    @Autowired
    private MyWebHandler handler;

    @Bean
    public RouterFunction<ServerResponse> timerRouter() {
        return route(RequestPredicates.GET("/date"), handler::getDate) // 普通获取时间
                       .andRoute(RequestPredicates.GET("/times"), handler::sendTimePerSec);  // 服务端推送
    }
}
